package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.corona.Game;
import com.corona.game.util.SpriteProxy;
import com.corona.game.util.TextureCache;
import java.util.Locale;
import java.util.Map;

/* compiled from: Battle.java */
/* access modifiers changed from: package-private */
/* loaded from: pokewilds.jar:com/pkmngen/game/DrawFriendlyHealthGen2.class */
public class DrawFriendlyHealthGen2 extends Action {
    public Action.Layer layer;
    SpriteProxy bgSprite;
    SpriteProxy healthSprite;
    SpriteProxy healthSpriteGreen;
    SpriteProxy healthSpriteYellow;
    SpriteProxy healthSpriteRed;
    char[] levelChars;
    SpriteProxy levelCharacter;
    Map<Character, SpriteProxy> textDict;
    int currHealth;
    int currHealthRemaining;
    Sprite helper;
    public static int xpBarIndex = 0;
    public static SpriteProxy[] xpBarAnim = new SpriteProxy[77];

    static {
        for (int i = 0; i < 77; i++) {
            xpBarAnim[i] = new SpriteProxy(TextureCache.get(Gdx.files.internal("attacks/xp_animation_gsc/output/frame-" + String.format(Locale.ROOT, "%03d", Integer.valueOf(i + 1)) + ".png")), 0, 0, 160, 144);
        }
    }

    public DrawFriendlyHealthGen2(Game game) {
        this(game, null);
    }

    public DrawFriendlyHealthGen2(Game game, Action nextAction) {
        super(new Object[0]);
        this.layer = Action.Layer.gui_129;
        this.nextAction = nextAction;
        this.healthSpriteGreen = new SpriteProxy(new Color(0.9375f, 0.8125f, 0.46875f, 1.0f), TextureCache.get(Gdx.files.internal("battle/gsc/health1.png")), 0, 0, 1, 2);
        this.healthSpriteYellow = new SpriteProxy(new Color(0.9375f, 0.8125f, 0.46875f, 1.0f), TextureCache.get(Gdx.files.internal("battle/gsc/health_yellow.png")), 0, 0, 1, 2);
        this.healthSpriteRed = new SpriteProxy(new Color(0.9375f, 0.8125f, 0.46875f, 1.0f), TextureCache.get(Gdx.files.internal("battle/gsc/health_red.png")), 0, 0, 1, 2);
        this.helper = new Sprite(TextureCache.get(Gdx.files.internal("battle/gsc/helper1.png")));
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "gui";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    public void updateHealthBarColor() {
        if (this.currHealth > 23) {
            this.healthSprite = this.healthSpriteGreen;
        } else if (this.currHealth > 10) {
            this.healthSprite = this.healthSpriteYellow;
        } else {
            this.healthSprite = this.healthSpriteRed;
        }
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        this.currHealth = (int) Math.ceil((double) ((((float) game.player.currPokemon.currentStats.get("hp").intValue()) * 48.0f) / ((float) game.player.currPokemon.maxStats.get("hp").intValue())));
        this.currHealthRemaining = game.player.currPokemon.currentStats.get("hp").intValue();
        game.battle.drawAction.drawFriendlyHealthAction = this;
        if (game.battle.drawAction instanceof RegigigasBattle.Draw) {
            this.textDict = game.textDictInverse;
            this.bgSprite = new SpriteProxy(Color.BLACK, TextureCache.get(Gdx.files.internal("battle/gsc/friendly_healthbar1_inverse.png")), 0, 0, 160, 144);
            this.levelCharacter = new SpriteProxy(Color.BLACK, TextureCache.get(Gdx.files.internal("battle/gsc/friendly_levelchar_inverse.png")), 0, 0, 160, 144);
        } else {
            this.textDict = game.textDict;
            this.bgSprite = new SpriteProxy(Color.WHITE, TextureCache.get(Gdx.files.internal("battle/gsc/friendly_healthbar1.png")), 0, 0, 160, 144);
            this.levelCharacter = new SpriteProxy(Color.WHITE, TextureCache.get(Gdx.files.internal("battle/gsc/friendly_levelchar.png")), 0, 0, 160, 144);
        }
        int currentLevelXp = game.player.currPokemon.calcExpForLevel(game.player.currPokemon.level);
        xpBarIndex = (int) (68.0f * (((float) (game.player.currPokemon.exp - currentLevelXp)) / ((float) (game.player.currPokemon.calcExpForLevel(game.player.currPokemon.level + 1) - currentLevelXp))));
        updateHealthBarColor();
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        if (this.nextAction != null) {
            game.insertAction(this.nextAction);
            this.nextAction = null;
        }
        if (DrawFriendlyHealth.shouldDraw) {
            game.uiBatch.draw(this.bgSprite, 0.0f, 0.0f);
            game.uiBatch.draw(xpBarAnim[xpBarIndex], 0.0f, 0.0f);
            char[] textArray = game.player.currPokemon.nickname.toUpperCase(Locale.ROOT).toCharArray();
            int offset = 0;
            if (textArray.length > 5) {
                offset = -16;
            } else if (textArray.length > 2) {
                offset = -8;
            }
            for (int i = 0; i < textArray.length; i++) {
                game.uiBatch.draw(this.textDict.get(Character.valueOf(textArray[i])), (float) (offset + 96 + (8 * i)), 80.0f);
            }
            if (game.player.currPokemon.status == null || game.player.currPokemon.status.equals("confuse") || game.player.currPokemon.status.equals("attract") || game.player.currPokemon.status.equals("curse")) {
                this.levelChars = String.valueOf(game.player.currPokemon.level).toCharArray();
                int offset2 = 0;
                if (this.levelChars.length < 3) {
                    game.uiBatch.draw(this.levelCharacter, 0.0f, 0.0f);
                    offset2 = 0 + 8;
                }
                for (char c : this.levelChars) {
                    game.uiBatch.draw(this.textDict.get(Character.valueOf(c)), (float) (112 + offset2), 72.0f);
                    offset2 += 8;
                }
            } else {
                String text = "";
                if (game.player.currPokemon.status.equals("poison") || game.player.currPokemon.status.equals("toxic")) {
                    text = "PSN";
                } else if (game.player.currPokemon.status.equals("paralyze")) {
                    text = "PAR";
                } else if (game.player.currPokemon.status.equals("freeze")) {
                    text = "FRZ";
                } else if (game.player.currPokemon.status.equals("sleep")) {
                    text = "SLP";
                } else if (game.player.currPokemon.status.equals("burn")) {
                    text = "BRN";
                }
                char[] textArray2 = text.toCharArray();
                for (int i2 = 0; i2 < textArray2.length; i2++) {
                    game.uiBatch.draw(this.textDict.get(Character.valueOf(textArray2[i2])), (float) (112 + (i2 * 8)), 72.0f);
                }
            }
            for (int i3 = 0; i3 < this.currHealth; i3++) {
                game.uiBatch.draw(this.healthSprite, (float) (96 + i3), 67.0f);
            }
            if (game.player.currPokemon.gender.equals("male")) {
                if (game.battle.drawAction instanceof RegigigasBattle.Draw) {
                    game.uiBatch.draw(TextureCache.maleSymbolInverse, 136.0f, 72.0f);
                } else {
                    game.uiBatch.draw(TextureCache.maleSymbol, 136.0f, 72.0f);
                }
            } else if (game.player.currPokemon.gender.equals("female")) {
                if (game.battle.drawAction instanceof RegigigasBattle.Draw) {
                    game.uiBatch.draw(TextureCache.femaleSymbolInverse, 136.0f, 72.0f);
                } else {
                    game.uiBatch.draw(TextureCache.femaleSymbol, 136.0f, 72.0f);
                }
            }
            int maxHealth = game.player.currPokemon.maxStats.get("hp").intValue();
            int hundredsPlace = maxHealth / 100;
            if (hundredsPlace > 0) {
                game.uiBatch.draw(this.textDict.get(Character.valueOf(Character.forDigit(hundredsPlace, 10))), 120.0f, 56.0f);
            }
            int tensPlace = (maxHealth % 100) / 10;
            if (tensPlace > 0 || hundredsPlace > 0) {
                game.uiBatch.draw(this.textDict.get(Character.valueOf(Character.forDigit(tensPlace, 10))), 128.0f, 56.0f);
            }
            game.uiBatch.draw(this.textDict.get(Character.valueOf(Character.forDigit(maxHealth % 10, 10))), 136.0f, 56.0f);
            int hundredsPlace2 = this.currHealthRemaining / 100;
            if (hundredsPlace2 > 0) {
                game.uiBatch.draw(this.textDict.get(Character.valueOf(Character.forDigit(hundredsPlace2, 10))), 88.0f, 56.0f);
            }
            int tensPlace2 = (this.currHealthRemaining % 100) / 10;
            if (tensPlace2 > 0 || hundredsPlace2 > 0) {
                game.uiBatch.draw(this.textDict.get(Character.valueOf(Character.forDigit(tensPlace2, 10))), 96.0f, 56.0f);
            }
            game.uiBatch.draw(this.textDict.get(Character.valueOf(Character.forDigit(this.currHealthRemaining % 10, 10))), 104.0f, 56.0f);
        }
        if (game.battle.drawAction == null) {
            game.actionStack.remove(this);
        }
    }
}
